************************************************************************************
**  Replication code for "Fiscal Incentives for Conflict"
**  Notes: District panel analysis of conflict outcomes (Tables 1, 2, A2-A17; Figures 1, A2, A5-A9)
*************************************************************************************
set more off

global mines = "F:/Dropbox (ESOC - Princeton)/Public services and conflict in India/Mining"

* Users can create separate folders for graphs and table output, the standard setting is to save all output in the main directory.
global mytables "$mines/Restat_Repository"
global myfigures "$mines/Restat_Repository"

cd "$mines/Restat_Repository"
u "FINAL_Replication_Conflict", replace


* Program ols_spatial_HAC and reg2hdfespatial if needed
capture program drop ols_spatial_HAC 
do "PROG_ols_spatial_HAC.ado"
capture program drop reg2hdfespatial 
do "PROG_regspatial.ado" 


xtset st_dist hdate



*-----------------------------
* Table 1: Summary statistics
*-----------------------------
*PANELS A,B, C

estimates clear

estpost summarize antiattack_d attack_d hyp_antiattack hyp_attack antiattack_pc attack_pc if mainsample_full 
estout using "$mytables/Table1_PanelA.tex", label cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2))") mlabels(none) collabels(none) style(tex) replace
estimates clear

estpost summarize log_irondep log_bauxdep log_coaldep irondepdum bauxitedepdum coaldepdum if hdate==94 & mainsample_full
estout using "$mytables/Table1_PanelB1.tex",  label cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2))") mlabels(none) collabels(none)  style(tex) replace
estimates clear

preserve
label var log_irondep "Log(Iron Deposit), positive"
label var log_bauxdep "Log(Bauxite Deposit), positive"
label var log_coaldep "Log(Coal Deposit), positive"
estpost summarize log_irondep if hdate==94 & mainsample_full==1 & irondepdum==1 
estout using "$mytables/Table1_PanelB2.tex",  label cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2))") mlabels(none) collabels(none)  style(tex) replace
estimates clear

estpost summarize log_bauxdep if hdate==94 & mainsample_full==1 & bauxdepdum==1 
estout using "$mytables/Table1_PanelB3.tex",  label cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2))") mlabels(none) collabels(none)  style(tex) replace
estimates clear

estpost summarize log_coaldep if hdate==94 & mainsample_full==1 & coaldepdum==1 
estout using "$mytables/Table1_PanelB4.tex",  label cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2))") mlabels(none) collabels(none)  style(tex) replace
estimates clear
restore


preserve
label var iron_price "Log Iron Price (real USD per MT)"
label var baux_price "Log Bauxite Price (real USD per MT)"
label var coal_price "Log Coal Price (real USD per MT)"
estpost summarize iron_price baux_price coal_price if st_dist==89 & mainsample_full==1
estout using "$mytables/Table1_PanelC.tex",  label cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2))") mlabels(none) collabels(none)  style(tex) replace
estimates clear
restore



*------------------------
*FIGURE 1: Event studies
*------------------------

set matsize 2000


keep if mainsample_full

matrix hrid = J(24 ,8, 0)

foreach measure in ""  { 

foreach mineral in  "iron"  "baux" "coal"  {

global mineraldum "irondepdum94 irondepdum95 irondepdum96 irondepdum97 irondepdum98 irondepdum99 irondepdum100 irondepdum101 irondepdum102 irondepdum103 irondepdum104 irondepdum105 irondepdum106 irondepdum107 bauxdepdum94 bauxdepdum95 bauxdepdum96 bauxdepdum97 bauxdepdum98 bauxdepdum99 bauxdepdum100 bauxdepdum101 bauxdepdum102 bauxdepdum103 bauxdepdum104 bauxdepdum105 bauxdepdum106 bauxdepdum107 coaldepdum94 coaldepdum95 coaldepdum96 coaldepdum97 coaldepdum98 coaldepdum99 coaldepdum100 coaldepdum101 coaldepdum102 coaldepdum103 coaldepdum104 coaldepdum105 coaldepdum106 coaldepdum107"
global mineral "irondep94 irondep95 irondep96 irondep97 irondep98 irondep99 irondep100 irondep101 irondep102 irondep103 irondep104 irondep105 irondep106 irondep107 bauxdep94 bauxdep95 bauxdep96 bauxdep97 bauxdep98 bauxdep99 bauxdep100 bauxdep101 bauxdep102 bauxdep103 bauxdep104 bauxdep105 bauxdep106 bauxdep107 coaldep94 coaldep95 coaldep96 coaldep97 coaldep98 coaldep99 coaldep100 coaldep101 coaldep102 coaldep103 coaldep104 coaldep105 coaldep106 coaldep107"

foreach outcome in "hyp_antiattack" "hyp_attack" {
preserve

if "`measure'"=="dum" {
ERROR
}

if "`measure'"=="" {
drop $mineraldum
global mineralcontrol=subinstr("$mineral","`mineral'dep`measure'94 `mineral'dep`measure'95 `mineral'dep`measure'96 `mineral'dep`measure'97 `mineral'dep`measure'98 `mineral'dep`measure'99 `mineral'dep`measure'100 `mineral'dep`measure'101 `mineral'dep`measure'102 `mineral'dep`measure'103 `mineral'dep`measure'104 `mineral'dep`measure'105 `mineral'dep`measure'106 `mineral'dep`measure'107","",.)
}


xi: xtreg `outcome' `mineral'dep`measure'94 `mineral'dep`measure'95 `mineral'dep`measure'96 o.`mineral'dep`measure'97 `mineral'dep`measure'98 `mineral'dep`measure'99 `mineral'dep`measure'100 `mineral'dep`measure'101 `mineral'dep`measure'102 `mineral'dep`measure'103 `mineral'dep`measure'104 `mineral'dep`measure'105 `mineral'dep`measure'106 `mineral'dep`measure'107  $mineral i.hdate_st, fe robust

qui lincom (`mineral'dep`measure'94+`mineral'dep`measure'95+`mineral'dep`measure'96+`mineral'dep`measure'97)/4
local mean1 = `r(estimate)'
local sd1 = `r(estimate)'


qui lincom (`mineral'dep`measure'98+`mineral'dep`measure'99+`mineral'dep`measure'100+`mineral'dep`measure'101+`mineral'dep`measure'102+`mineral'dep`measure'103)/6
local mean2 = `r(estimate)'
local sd2 = `r(estimate)'

qui lincom (`mineral'dep`measure'104+`mineral'dep`measure'105+`mineral'dep`measure'106+`mineral'dep`measure'107)/4
local mean3 = `r(estimate)'
local sd3 = `r(estimate)'


global iter  = 1
forvalues i=94(1)107 {
  qui lincom  `mineral'dep`measure'`i'
  matrix hrid[$iter,3] = `r(estimate)'
  matrix hrid[$iter,2] = `r(estimate)' - 1.98 * `r(se)'
  matrix hrid[$iter,4] = `r(estimate)'+ 1.98* `r(se)'
  local ttt=`i'-98
  matrix hrid[$iter, 1] = `ttt'
  matrix hrid[$iter, 5] = 1

  
  matrix hrid[$iter, 7] = `mean1'
  matrix hrid[$iter, 6] = `mean1'-1.98*`sd1'
  matrix hrid[$iter, 8] = `mean1'+1.98*`sd1'
	if `i'>=98 {
	matrix hrid[$iter, 7] = `mean2'
	matrix hrid[$iter, 6] = `mean2'-1.98*`sd2'
	matrix hrid[$iter, 8] = `mean2'+1.98*`sd2'
	}
	if `i'>=104 {
	matrix hrid[$iter, 7] = `mean3'
	matrix hrid[$iter, 6] = `mean3'-1.98*`sd3'
	matrix hrid[$iter, 8] = `mean3'+1.98*`sd3'
	}


  global iter=$iter+1
  }

  svmat hrid
sort hrid1

if "`outcome'"=="hyp_antiattack" {
qui su hrid2
local ymin = floor(`r(min)'*10)/10
qui su hrid4
local ymax = ceil(`r(max)'*10)/10
}
display("`miny'"+"`maxy'")
drop if hrid1==0 & hrid2==0 & hrid3==0 & hrid5==0

qui su hrid1
sort hrid1
twoway (connected hrid3 hrid1 ,ytitle("Coefficient estimate", size(6) axis(1))) (rcap hrid2 hrid4 hrid1 , lcolor(gs6) lwidth(vthin) xline(-0.5,lcolor(gs6)))  (line hrid7 hrid1 if hrid1<0, col(gs6) lp(dash) lwidth(thin))  (line hrid7 hrid1 if hrid1>=0 & hrid1<6, col(gs6) lp(dash) lwidth(thin))  (line hrid7 hrid1 if hrid1>=6, col(gs6) lp(dash) lwidth(thin)), name(`mineral'`measure'`outcome', replace) scheme(s1mono) legend(off) xtitle("Half-years to treatment", size(6)) xscale(range(`r(min)' `r(max)')) yscale(range(`ymin' `ymax')) ylabel(`ymin'(.1)`ymax', labsize(4))  xlabel(`r(min)'[1]`r(max)', labsize(4)) yline(0, lp(dot) lwidth(vthin))  

drop hrid*
graph export "$myfigures/Figure1_`outcome'_`mineral'.png", replace
graph drop _all
restore
}
}
}


*---------------------
*TABLE 2: MAIN RESULTS
*---------------------
* Also produces p-value on the iron-bauxite difference reported in footnote 37

preserve
keep if mainsample_window==1

lab var iron_value "Log(Iron Deposit) \\ x Price (real USD per MT)"
lab var baux_value "Log(Bauxite Deposit) \\ x Price (real USD per MT)"
lab var coal_value "Log(Coal Deposit) \\ x Price (real USD per MT)"

local main "log_irondep_post iron_value"
local mainplus "log_irondep_post log_bauxdep_post log_coaldep_post iron_value baux_value coal_value"


 eststo: reghdfe antiattack_d `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_antiattack `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe hyp_antiattack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		test 0.76*log_bauxdep_post-1.02*log_irondep_post=0
		* Test reported in footnote 37
 eststo: reghdfe attack_d `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

esttab using "$mytables/Table2.tex", keep(`mainplus')  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(ymean N N_clust, labels("Mean DV" "Observations" "Clusters") fmt(3 0 0))   replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore
		test 0.76*log_bauxdep_post-1.02*log_irondep_post=0
		* Test reported in footnote 37

*------------------------------------------
* FIGURE A2: Panel B: World Mineral Prices
*------------------------------------------

preserve
xtset st_dist hdate
keep if irondepdum==1 & bauxdepdum==1 & coaldepdum==1
twoway (connected iron_price_st hdate if irondepdum!=0 & (inrange(hdate,94,107)) ) ///
(connected baux_price_st hdate if bauxdepdum!=0 & (inrange(hdate,94,107))) ///
(connected coal_price_st hdate if coaldepdum!=0 & (inrange(hdate,94,107))), scheme(s1color)
graph export "$myfigures/FigureA2_PanelB.pdf", replace
restore



*---------------------------------------------------------------
* FIGURE A5: Panel D: Distribution of Iron Ore Deposit measure
*---------------------------------------------------------------

preserve
histogram log_irondep if hdate==94 & mainsample_full==1 & irondepdum==1, scheme(s1mono)
graph export "$myfigures/FigureA5_PanelD.pdf", replace
restore



*---------------------------------------------------------------
* FIGURE A6: Event studies for Iron Ore Deposits
*---------------------------------------------------------------
* Also calculates p-values reported in the figure note.

set matsize 2000

graph drop _all

matrix hrid = J(24 ,8, 0)
foreach outcome in  "antiattack_d" "attack_d" "hyp_antiattack"  "hyp_attack"    {

foreach measure in ""  { 

foreach mineral in "iron"  {
preserve
global mineralcontroldum "irondepdum94 irondepdum95 irondepdum96 irondepdum97 irondepdum98 irondepdum99 irondepdum100 irondepdum101 irondepdum102 irondepdum103 irondepdum104 irondepdum105 irondepdum106 irondepdum107 bauxdepdum94 bauxdepdum95 bauxdepdum96 bauxdepdum97 bauxdepdum98 bauxdepdum99 bauxdepdum100 bauxdepdum101 bauxdepdum102 bauxdepdum103 bauxdepdum104 bauxdepdum105 bauxdepdum106 bauxdepdum107 coaldepdum94 coaldepdum95 coaldepdum96 coaldepdum97 coaldepdum98 coaldepdum99 coaldepdum100 coaldepdum101 coaldepdum102 coaldepdum103 coaldepdum104 coaldepdum105 coaldepdum106 coaldepdum107"
global mineralcontrol "irondep94 irondep95 irondep96 irondep97 irondep98 irondep99 irondep100 irondep101 irondep102 irondep103 irondep104 irondep105 irondep106 irondep107 bauxdep94 bauxdep95 bauxdep96 bauxdep97 bauxdep98 bauxdep99 bauxdep100 bauxdep101 bauxdep102 bauxdep103 bauxdep104 bauxdep105 bauxdep106 bauxdep107 coaldep94 coaldep95 coaldep96 coaldep97 coaldep98 coaldep99 coaldep100 coaldep101 coaldep102 coaldep103 coaldep104 coaldep105 coaldep106 coaldep107"

if "`measure'"=="dum" {
ERROR
}

if "`measure'"=="" {
local underrange=-0.2
local upperrange=0.3
drop $mineralcontroldum
global mineralcontrol=subinstr("$mineralcontrol","`mineral'dep`measure'94 `mineral'dep`measure'95 `mineral'dep`measure'96 `mineral'dep`measure'97 `mineral'dep`measure'98 `mineral'dep`measure'99 `mineral'dep`measure'100 `mineral'dep`measure'101 `mineral'dep`measure'102 `mineral'dep`measure'103 `mineral'dep`measure'104 `mineral'dep`measure'105 `mineral'dep`measure'106 `mineral'dep`measure'107","",.)
display("$mineralcontrol")
}

qui xi: xtreg `outcome' `mineral'dep`measure'94 `mineral'dep`measure'95 `mineral'dep`measure'96 o.`mineral'dep`measure'97 `mineral'dep`measure'98 `mineral'dep`measure'99 `mineral'dep`measure'100 `mineral'dep`measure'101 `mineral'dep`measure'102 `mineral'dep`measure'103 `mineral'dep`measure'104 `mineral'dep`measure'105 `mineral'dep`measure'106 `mineral'dep`measure'107  $mineralcontrol i.hdate_st, fe robust

test `mineral'dep`measure'94 `mineral'dep`measure'95 `mineral'dep`measure'96 `mineral'dep`measure'97
* This p-value is reported in the notes to figure A6

qui lincom (`mineral'dep`measure'94+`mineral'dep`measure'95+`mineral'dep`measure'96+`mineral'dep`measure'97)/4

local mean1 = `r(estimate)'
local sd1 = `r(estimate)'


qui lincom (`mineral'dep`measure'98+`mineral'dep`measure'99+`mineral'dep`measure'100+`mineral'dep`measure'101+`mineral'dep`measure'102+`mineral'dep`measure'103)/6
local mean2 = `r(estimate)'
local sd2 = `r(estimate)'

qui lincom (`mineral'dep`measure'104+`mineral'dep`measure'105+`mineral'dep`measure'106+`mineral'dep`measure'107)/4
local mean3 = `r(estimate)'
local sd3 = `r(estimate)'

global iter  = 1
forvalues i=94(1)107 {
 qui  lincom  `mineral'dep`measure'`i'
  matrix hrid[$iter,3] = `r(estimate)'
  matrix hrid[$iter,2] = `r(estimate)' - 1.98 * `r(se)'
  matrix hrid[$iter,4] = `r(estimate)'+ 1.98* `r(se)'
  local ttt=`i'-98
  matrix hrid[$iter, 1] = `ttt'
  matrix hrid[$iter, 5] = 1

  
  matrix hrid[$iter, 7] = `mean1'
  matrix hrid[$iter, 6] = `mean1'-1.98*`sd1'
  matrix hrid[$iter, 8] = `mean1'+1.98*`sd1'
	if `i'>=98 {
	matrix hrid[$iter, 7] = `mean2'
	matrix hrid[$iter, 6] = `mean2'-1.98*`sd2'
	matrix hrid[$iter, 8] = `mean2'+1.98*`sd2'
	}
	if `i'>=104 {
	matrix hrid[$iter, 7] = `mean3'
	matrix hrid[$iter, 6] = `mean3'-1.98*`sd3'
	matrix hrid[$iter, 8] = `mean3'+1.98*`sd3'
	}


  global iter=$iter+1
  }

  svmat hrid
sort hrid1

qui su hrid2
local miny = `r(min)'
qui su hrid4
local maxy = `r(max)'
drop if hrid1==0 & hrid2==0 & hrid3==0 & hrid5==0
qui su hrid1
sort hrid1
qui twoway (connected hrid3 hrid1 ,ytitle("Coefficient estimate", axis(1))) (rcap hrid2 hrid4 hrid1 , lcolor(gs4) lwidth(vthin) xline(-0.5,lcolor(red)))  (line hrid7 hrid1 if hrid1<0, col(blue) lp(dash) lwidth(thin))  (line hrid7 hrid1 if hrid1>=0 & hrid1<6, col(blue) lp(dash) lwidth(thin))  (line hrid7 hrid1 if hrid1>=6, col(blue) lp(dash) lwidth(thin)), name(`mineral'`measure'`outcome', replace) scheme(s1mono) legend(off) xtitle("Half-years to treatment", size(4)) xscale(range(`r(min)' `r(max)')) xlabel(`r(min)'[1]`r(max)') yline(0, lp(dot) lwidth(vthin)) yscale(range(`underrange' `upperrange')) yla(`underrange'(0.1)`upperrange')  
graph export "$myfigures/FigureA6_`outcome'.png", replace
graph drop _all

drop hrid*
restore
}

}
}




*----------------------------------------------------------------------------------
* FIGURE A7: Event studies for Iron Ore Deposits - dummy mining measure
*----------------------------------------------------------------------------------


set matsize 2000

graph drop _all

matrix hrid = J(24 ,8, 0)
foreach outcome in  "hyp_antiattack"  "hyp_attack"  "antiattack_d" "attack_d"  {

foreach measure in "dum"  { 

foreach mineral in "iron"  {
preserve
global mineralcontroldum "irondepdum94 irondepdum95 irondepdum96 irondepdum97 irondepdum98 irondepdum99 irondepdum100 irondepdum101 irondepdum102 irondepdum103 irondepdum104 irondepdum105 irondepdum106 irondepdum107 bauxdepdum94 bauxdepdum95 bauxdepdum96 bauxdepdum97 bauxdepdum98 bauxdepdum99 bauxdepdum100 bauxdepdum101 bauxdepdum102 bauxdepdum103 bauxdepdum104 bauxdepdum105 bauxdepdum106 bauxdepdum107 coaldepdum94 coaldepdum95 coaldepdum96 coaldepdum97 coaldepdum98 coaldepdum99 coaldepdum100 coaldepdum101 coaldepdum102 coaldepdum103 coaldepdum104 coaldepdum105 coaldepdum106 coaldepdum107"
global mineralcontrol "irondep94 irondep95 irondep96 irondep97 irondep98 irondep99 irondep100 irondep101 irondep102 irondep103 irondep104 irondep105 irondep106 irondep107 bauxdep94 bauxdep95 bauxdep96 bauxdep97 bauxdep98 bauxdep99 bauxdep100 bauxdep101 bauxdep102 bauxdep103 bauxdep104 bauxdep105 bauxdep106 bauxdep107 coaldep94 coaldep95 coaldep96 coaldep97 coaldep98 coaldep99 coaldep100 coaldep101 coaldep102 coaldep103 coaldep104 coaldep105 coaldep106 coaldep107"

if "`measure'"=="dum" {
local underrange=-0.5
local upperrange=0.5
drop $mineralcontrol
global mineralcontrol=subinstr("$mineralcontroldum","`mineral'dep`measure'94 `mineral'dep`measure'95 `mineral'dep`measure'96 `mineral'dep`measure'97 `mineral'dep`measure'98 `mineral'dep`measure'99 `mineral'dep`measure'100 `mineral'dep`measure'101 `mineral'dep`measure'102 `mineral'dep`measure'103 `mineral'dep`measure'104 `mineral'dep`measure'105 `mineral'dep`measure'106 `mineral'dep`measure'107","",.)
display("$mineralcontrol")
}


if "`measure'"=="" {
ERROR
}

xi: xtreg `outcome' `mineral'dep`measure'94 `mineral'dep`measure'95 `mineral'dep`measure'96 o.`mineral'dep`measure'97 `mineral'dep`measure'98 `mineral'dep`measure'99 `mineral'dep`measure'100 `mineral'dep`measure'101 `mineral'dep`measure'102 `mineral'dep`measure'103 `mineral'dep`measure'104 `mineral'dep`measure'105 `mineral'dep`measure'106 `mineral'dep`measure'107 $mineralcontrol i.hdate_st, fe robust

qui lincom (`mineral'dep`measure'94+`mineral'dep`measure'95+`mineral'dep`measure'96+`mineral'dep`measure'97)/4

local mean1 = `r(estimate)'
local sd1 = `r(estimate)'


qui lincom (`mineral'dep`measure'98+`mineral'dep`measure'99+`mineral'dep`measure'100+`mineral'dep`measure'101+`mineral'dep`measure'102+`mineral'dep`measure'103)/6
local mean2 = `r(estimate)'
local sd2 = `r(estimate)'

qui lincom (`mineral'dep`measure'104+`mineral'dep`measure'105+`mineral'dep`measure'106+`mineral'dep`measure'107)/4
local mean3 = `r(estimate)'
local sd3 = `r(estimate)'

global iter  = 1
forvalues i=94(1)107 {
  qui lincom  `mineral'dep`measure'`i'
  matrix hrid[$iter,3] = `r(estimate)'
  matrix hrid[$iter,2] = `r(estimate)' - 1.98 * `r(se)'
  matrix hrid[$iter,4] = `r(estimate)'+ 1.98* `r(se)'
  local ttt=`i'-98
  matrix hrid[$iter, 1] = `ttt'
  matrix hrid[$iter, 5] = 1

  
  matrix hrid[$iter, 7] = `mean1'
  matrix hrid[$iter, 6] = `mean1'-1.98*`sd1'
  matrix hrid[$iter, 8] = `mean1'+1.98*`sd1'
	if `i'>=98 {
	matrix hrid[$iter, 7] = `mean2'
	matrix hrid[$iter, 6] = `mean2'-1.98*`sd2'
	matrix hrid[$iter, 8] = `mean2'+1.98*`sd2'
	}
	if `i'>=104 {
	matrix hrid[$iter, 7] = `mean3'
	matrix hrid[$iter, 6] = `mean3'-1.98*`sd3'
	matrix hrid[$iter, 8] = `mean3'+1.98*`sd3'
	}


  global iter=$iter+1
  }

  svmat hrid
sort hrid1

qui su hrid2
local miny = `r(min)'
qui su hrid4
local maxy = `r(max)'
drop if hrid1==0 & hrid2==0 & hrid3==0 & hrid5==0

qui su hrid1
sort hrid1
qui twoway (connected hrid3 hrid1 ,ytitle("Coefficient estimate", axis(1))) (rcap hrid2 hrid4 hrid1 , lcolor(gs4) lwidth(vthin) xline(-0.5,lcolor(red)))  (line hrid7 hrid1 if hrid1<0, col(blue) lp(dash) lwidth(thin))  (line hrid7 hrid1 if hrid1>=0 & hrid1<6, col(blue) lp(dash) lwidth(thin))  (line hrid7 hrid1 if hrid1>=6, col(blue) lp(dash) lwidth(thin)), name(`mineral'`measure'`outcome', replace) scheme(s1mono) legend(off) xtitle("Half-years to treatment", size(4)) xscale(range(`r(min)' `r(max)')) xlabel(`r(min)'[1]`r(max)') yline(0, lp(dot) lwidth(vthin)) yscale(range(`underrange' `upperrange')) yla(`underrange'(0.1)`upperrange')  
graph export "$myfigures/FigureA7_`outcome'.png", replace
graph drop _all
drop hrid*
restore
}


}
}



*---------------------------------------------------------------
* FIGURE A8-9: Event studies for three minerals - Comparison
*---------------------------------------------------------------


set matsize 2000

graph drop _all

matrix hrid = J(24 ,8, 0)
foreach outcome in "hyp_antiattack"  "hyp_attack"  "antiattack_d" "attack_d"   {

foreach measure in ""  { 

foreach mineral in "iron" "baux" "coal"  {
preserve
global mineralcontroldum "irondepdum94 irondepdum95 irondepdum96 irondepdum97 irondepdum98 irondepdum99 irondepdum100 irondepdum101 irondepdum102 irondepdum103 irondepdum104 irondepdum105 irondepdum106 irondepdum107 bauxdepdum94 bauxdepdum95 bauxdepdum96 bauxdepdum97 bauxdepdum98 bauxdepdum99 bauxdepdum100 bauxdepdum101 bauxdepdum102 bauxdepdum103 bauxdepdum104 bauxdepdum105 bauxdepdum106 bauxdepdum107 coaldepdum94 coaldepdum95 coaldepdum96 coaldepdum97 coaldepdum98 coaldepdum99 coaldepdum100 coaldepdum101 coaldepdum102 coaldepdum103 coaldepdum104 coaldepdum105 coaldepdum106 coaldepdum107"
global mineralcontrol "irondep94 irondep95 irondep96 irondep97 irondep98 irondep99 irondep100 irondep101 irondep102 irondep103 irondep104 irondep105 irondep106 irondep107 bauxdep94 bauxdep95 bauxdep96 bauxdep97 bauxdep98 bauxdep99 bauxdep100 bauxdep101 bauxdep102 bauxdep103 bauxdep104 bauxdep105 bauxdep106 bauxdep107 coaldep94 coaldep95 coaldep96 coaldep97 coaldep98 coaldep99 coaldep100 coaldep101 coaldep102 coaldep103 coaldep104 coaldep105 coaldep106 coaldep107"


if "`measure'"=="dum" {
ERROR
}

if "`measure'"=="" {
sum log_`mineral'dep if `mineral'depdum==1 & hdate==96,d
display(r(sd))
forvalues k=94/107 {
replace `mineral'dep`measure'`k'=`mineral'dep`measure'`k'/r(sd)
}
local underrange=-0.2
local upperrange=0.5
drop $mineralcontroldum
global mineralcontrol=subinstr("$mineralcontrol","`mineral'dep`measure'94 `mineral'dep`measure'95 `mineral'dep`measure'96 `mineral'dep`measure'97 `mineral'dep`measure'98 `mineral'dep`measure'99 `mineral'dep`measure'100 `mineral'dep`measure'101 `mineral'dep`measure'102 `mineral'dep`measure'103 `mineral'dep`measure'104 `mineral'dep`measure'105 `mineral'dep`measure'106 `mineral'dep`measure'107","",.)
display("$mineralcontrol")
}
display("here")
display("here")

qui xi: xtreg `outcome' `mineral'dep`measure'94 `mineral'dep`measure'95 `mineral'dep`measure'96 o.`mineral'dep`measure'97 `mineral'dep`measure'98 `mineral'dep`measure'99 `mineral'dep`measure'100 `mineral'dep`measure'101 `mineral'dep`measure'102 `mineral'dep`measure'103 `mineral'dep`measure'104 `mineral'dep`measure'105 `mineral'dep`measure'106 `mineral'dep`measure'107 $mineralcontrol i.hdate_st, fe robust

qui lincom (`mineral'dep`measure'94+`mineral'dep`measure'95+`mineral'dep`measure'96+`mineral'dep`measure'97)/4

local mean1 = `r(estimate)'
local sd1 = `r(estimate)'


qui lincom (`mineral'dep`measure'98+`mineral'dep`measure'99+`mineral'dep`measure'100+`mineral'dep`measure'101+`mineral'dep`measure'102+`mineral'dep`measure'103)/6
local mean2 = `r(estimate)'
local sd2 = `r(estimate)'

qui lincom (`mineral'dep`measure'104+`mineral'dep`measure'105+`mineral'dep`measure'106+`mineral'dep`measure'107)/4
local mean3 = `r(estimate)'
local sd3 = `r(estimate)'

global iter  = 1
forvalues i=94(1)107 {
  qui lincom  `mineral'dep`measure'`i'
  matrix hrid[$iter,3] = `r(estimate)'
  matrix hrid[$iter,2] = `r(estimate)' - 1.98 * `r(se)'
  matrix hrid[$iter,4] = `r(estimate)'+ 1.98* `r(se)'
  local ttt=`i'-98
  matrix hrid[$iter, 1] = `ttt'
  matrix hrid[$iter, 5] = 1

  
  matrix hrid[$iter, 7] = `mean1'
  matrix hrid[$iter, 6] = `mean1'-1.98*`sd1'
  matrix hrid[$iter, 8] = `mean1'+1.98*`sd1'
	if `i'>=98 {
	matrix hrid[$iter, 7] = `mean2'
	matrix hrid[$iter, 6] = `mean2'-1.98*`sd2'
	matrix hrid[$iter, 8] = `mean2'+1.98*`sd2'
	}
	if `i'>=104 {
	matrix hrid[$iter, 7] = `mean3'
	matrix hrid[$iter, 6] = `mean3'-1.98*`sd3'
	matrix hrid[$iter, 8] = `mean3'+1.98*`sd3'
	}


  global iter=$iter+1
  }

  svmat hrid
sort hrid1

qui su hrid2
local miny = `r(min)'
qui su hrid4
local maxy = `r(max)'
drop if hrid1==0 & hrid2==0 & hrid3==0 & hrid5==0

qui su hrid1
sort hrid1
qui twoway (connected hrid3 hrid1 ,ytitle("Coefficient estimate", axis(1))) (rcap hrid2 hrid4 hrid1 , lcolor(gs4) lwidth(vthin) xline(-0.5,lcolor(red)))  (line hrid7 hrid1 if hrid1<0, col(blue) lp(dash) lwidth(thin))  (line hrid7 hrid1 if hrid1>=0 & hrid1<6, col(blue) lp(dash) lwidth(thin))  (line hrid7 hrid1 if hrid1>=6, col(blue) lp(dash) lwidth(thin)), name(`mineral'`measure'`outcome', replace) scheme(s1mono) legend(off) xtitle("Half-years to treatment", size(4)) xscale(range(`r(min)' `r(max)')) xlabel(`r(min)'[1]`r(max)') yline(0, lp(dot) lwidth(vthin)) yscale(range(`underrange' `upperrange')) yla(`underrange'(0.1)`upperrange')  

drop hrid*
restore
}
graph combine iron`measure'`outcome' baux`measure'`outcome' coal`measure'`outcome', cols(3) xsize(3) ysize(1) scheme(s1mono) 
graph export "$myfigures/FigureA8_`outcome'`measure'.png", replace
graph drop _all

}
}



*-----------------------------------------
* TABLE A2: Additional Summary Statistics
*-----------------------------------------

estpost summarize  manganesedepdum chromitedepdum r_tot_lit_rate r_tot_scst_rate percentageforest dist_pct_app_pr pop_dens r_share dist_pct_power r_tot_anyag_rate percentage_drought  if hdate==94 & mainsample_full 
estout using "$mytables/TableA2.tex",  label cells("count(fmt(0)) mean(fmt(2)) sd(fmt(2))") mlabels(none) collabels(none)  style(tex) replace


*-----------------------------------
*TABLE A3: Pre-treatment balance
*-----------------------------------

preserve

keep if hdate<96 & mainsample_full==1 

bys st_code dist_code: egen antiattack_av=sum(antiattack)
bys st_code dist_code: egen attack_av=sum(attack)

gen antiattack_av_pc=antiattack_av*1000000/tot_pop
gen attack_av_pc=attack*1000000/tot_pop

sum r_tot_scst_rate

estimates clear

eststo: reg antiattack_av_pc log_irondep log_bauxdep log_coaldep i.st_code if hdate==94   ,robust
		estadd ysumm

eststo: reg attack_av_pc log_irondep log_bauxdep log_coaldep i.st_code if hdate==94  , robust
		estadd ysumm

eststo: reg log_irondep percentageforest i.st_code if hdate==94,robust
		estadd ysumm

eststo: reg log_irondep pop_dens i.st_code if hdate==94,robust
		estadd ysumm

eststo: reg log_irondep r_tot_lit_rate i.st_code if hdate==94,robust
		estadd ysumm		

eststo: reg log_irondep r_tot_scst_rate i.st_code if hdate==94,robust
		estadd ysumm
		
eststo: reg log_irondep dist_pct_app_pr i.st_code if hdate==94,robust
		estadd ysumm
		
eststo: reg log_irondep dist_pct_power i.st_code if hdate==94,robust
		estadd ysumm

eststo: reg log_irondep percentage_drought i.st_code if hdate==94,robust
		estadd ysumm

eststo: reg log_irondep r_tot_anyag_rate i.st_code if hdate==94,robust
		estadd ysumm

eststo: reg log_irondep r_share i.st_code if hdate==94,robust
		estadd ysumm
		
esttab using "$mytables/TableA3.tex", keep(log_irondep log_bauxdep log_coaldep dist_pct_app_pr r_tot_lit_rate r_tot_scst_rate percentageforest pop_dens dist_pct_power_supl r_share r_tot_anyag_rate percentage_drought) stats(ymean ysd N, labels("Mean DV" "Standard Deviation" "Observations") fmt(3 3 0 ))  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label  replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore


*---------------------------------------
*TABLE A4: CONTROL x POST INTERACTIONS 
*---------------------------------------


preserve
keep if mainsample_window==1

local main "log_irondep_post iron_value"
local mainplus "log_irondep_post log_bauxdep_post log_coaldep_post iron_value baux_value coal_value"
local timeint "i.post|percentageforest i.post|dist_pct_app_pr i.post|r_tot_scst_rate i.post|r_tot_lit i.post|pop_dens i.post|percentage_drought i.post|dist_pct_power i.post|r_share i.post|r_tot_anyag_rate"

 eststo: xi: reghdfe antiattack_d `main' `timeint', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo:xi: reghdfe hyp_antiattack `main' `timeint', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo:xi: reghdfe hyp_antiattack `mainplus' `timeint', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: xi: reghdfe attack_d `main' `timeint', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm


 eststo: xi: reghdfe hyp_attack `main' `timeint', a(hdate_st st_dist) cluster(st_dist)
			estadd ysumm


 eststo: xi: reghdfe hyp_attack `mainplus' `timeint', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm		

esttab using "$mytables/TableA4.tex",  keep(log_irondep_post log_bauxdep_post log_coaldep_post)  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(ymean ysd N N_clust, labels("Mean DV" "Standard Deviation" "Observations" "Clusters") fmt(3 3 0 0)) replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore



*-------------------------------------------
*TABLE A5: Main results with IAP controls 
*-------------------------------------------

preserve

keep if mainsample_window==1

local main "log_irondep_post iron_value"
local mainplus "log_irondep_post log_bauxdep_post log_coaldep_post  iron_value baux_value coal_value"

gen log_NoofProjSanctioned=log((NumberofProjectssanctioned12+1)*100000/r_tot_pop)
gen log_NoofProjTakenup=log((NumberofProjectstakenup12+1)*100000/r_tot_pop)
gen log_NoofProjCompleted=log((NumberofProjectsCompleted12+1)*100000/r_tot_pop)
gen log_ExpenditureinRsLakh=log((ExpenditureinRsLakh12+1)*100000/r_tot_pop)


 
 eststo: reghdfe hyp_antiattack  `mainplus' if any_iap, a(c.log_NoofProjSanctioned#hdate hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_antiattack `mainplus' if any_iap , a(c.log_NoofProjCompleted#hdate hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe hyp_antiattack `mainplus' if any_iap, a(c.log_NoofProjTakenup#hdate hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe hyp_antiattack  `mainplus' if any_iap, a(c.log_ExpenditureinRsLakh#hdate hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `mainplus' if any_iap, a(c.log_NoofProjSanctioned#hdate hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `mainplus' if any_iap, a(c.log_NoofProjCompleted#hdate hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `mainplus' if any_iap, a(c.log_NoofProjTakenup#hdate hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `mainplus' if any_iap, a(c.log_ExpenditureinRsLakh#hdate hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
esttab using "$mytables/TableA5.tex", keep(log_irondep_post log_bauxdep_post log_coaldep_post)  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(ymean ysd N N_clust, labels("Mean DV" "Standard Deviation" "Observations" "Clusters") fmt(3 3 0 0))   replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore




*----------------------------------------------
*TABLE A6:Main results with price interaction
*----------------------------------------------


preserve
keep if mainsample_window==1

bys st_dist: egen iron_price_av=mean(log(q_avg_p_iron))
bys st_dist: egen baux_price_av=mean(log(q_avg_p_baux))
bys st_dist: egen coal_price_av=mean(log(q_avg_p_coal))

gen iron_value_st=log_irondep*(log(q_avg_p_iron)-iron_price_av)
gen baux_value_st=log_bauxdep*(log(q_avg_p_baux)-baux_price_av)
gen coal_value_st=log_coaldep*(log(q_avg_p_coal)-coal_price_av)

gen iron_value_st_post=iron_value_st*post
gen baux_value_st_post=baux_value_st*post
gen coal_value_st_post=coal_value_st*post

label var iron_value_st "Log(Iron Deposit) x Price"
lab var baux_value_st "Log(Bauxite Deposit) x Price"
lab var coal_value_st "Log(Coal Deposit) x Price"
label var  iron_value_st_post "Log(Iron Deposit) x Price x Post"
label var  baux_value_st_post "Log(Bauxite Deposit) x Price x Post"
label var  coal_value_st_post "Log(Coal Deposit) x Price x Post"

local main "log_irondep_post iron_value_st iron_value_st_post"
local mainplus "log_irondep_post log_bauxdep_post log_coaldep_post  iron_value_st iron_value_st_post baux_value_st baux_value_st_post coal_value_st coal_value_st_post"

estimates clear

 eststo: reghdfe antiattack_d `main', a(hdate_st st_dist) cluster(st_dist)

test  log_irondep_post iron_value_st_post
		estadd scalar p_value = r(p)

 eststo: reghdfe hyp_antiattack `main', a(hdate_st st_dist) cluster(st_dist)

 test  log_irondep_post iron_value_st_post
		estadd scalar p_value =  r(p)
		

 eststo: reghdfe hyp_antiattack `mainplus', a(hdate_st st_dist) cluster(st_dist)

 test  log_irondep_post iron_value_st_post
		estadd scalar p_value = r(p)


 eststo: reghdfe attack_d `main', a(hdate_st st_dist) cluster(st_dist)

 test  log_irondep_post iron_value_st_post
		estadd scalar p_value =  r(p)
		
 eststo: reghdfe hyp_attack `main', a(hdate_st st_dist) cluster(st_dist)

 test  log_irondep_post iron_value_st_post
		estadd scalar p_value =  r(p)

 eststo: reghdfe hyp_attack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		
 test  log_irondep_post iron_value_st_post
		estadd scalar p_value =  r(p)

esttab using "$mytables/TableA6.tex", keep(log_irondep_post log_bauxdep_post log_coaldep_post  iron_value_st iron_value_st_post baux_value_st baux_value_st_post coal_value_st coal_value_st_post)  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(p_value N N_clust, labels("F-test on Post terms for Iron Ore (p-value)" "Observations" "Clusters") fmt(3 0 0))   replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(3)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore


*--------------------------------------------------
*TABLE A7: Main Results with Conley standard errors 
*--------------------------------------------------


preserve
keep if mainsample_window==1

 eststo: reg2hdfespatial antiattack_d log_irondep_post iron_value, lat(_Y) lon(_X) timevar(hdate) panelvar(st_dist) distcutoff(250) lagcutoff(10) altfetime(hdate_st)

 eststo: reg2hdfespatial hyp_antiattack log_irondep_post iron_value, lat(_Y) lon(_X) timevar(hdate) panelvar(st_dist) distcutoff(250) lagcutoff(10) altfetime(hdate_st)

 eststo: reg2hdfespatial hyp_antiattack log_irondep_post log_bauxdep_post log_coaldep_post iron_value baux_value coal_value, lat(_Y) lon(_X) timevar(hdate) panelvar(st_dist) distcutoff(250) lagcutoff(10) altfetime(hdate_st)

 eststo: reg2hdfespatial attack_d log_irondep_post iron_value, lat(_Y) lon(_X) timevar(hdate) panelvar(st_dist) distcutoff(250) lagcutoff(10) altfetime(hdate_st)

 eststo: reg2hdfespatial hyp_attack log_irondep_post iron_value, lat(_Y) lon(_X) timevar(hdate) panelvar(st_dist) distcutoff(250) lagcutoff(10) altfetime(hdate_st)

 eststo: reg2hdfespatial hyp_attack log_irondep_post log_bauxdep_post log_coaldep_post iron_value baux_value coal_value, lat(_Y) lon(_X) timevar(hdate) panelvar(st_dist) distcutoff(250) lagcutoff(10) altfetime(hdate_st)

esttab using "$mytables/TableA7.tex", keep(log_irondep_post log_bauxdep_post log_coaldep_post)  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(N, labels("Observations") fmt(0))   replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")

restore
estimates clear



*-----------------------------------------------------------
*TABLE A8: Main Results for per capita violence outcomes 
*-----------------------------------------------------------


preserve
keep if mainsample_window==1

local main "log_irondep_post iron_value"
local mainplus "log_irondep_post log_bauxdep_post log_coaldep_post iron_value baux_value coal_value"


 eststo: reghdfe antiattack_pc `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe antiattack_pc `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe attack_pc `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe attack_pc `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

esttab using "$mytables/TableA8.tex", keep(log_irondep_post log_bauxdep_post log_coaldep_post)  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(ymean ysd N N_clust, labels("Mean DV" "Standard Deviation" "Observations" "Clusters") fmt(3 3 0 0))   replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore



*----------------------------------------
*TABLE A9: Main Results in Poisson model
*----------------------------------------

preserve

keep if mainsample_window

local mainplus "log_irondep_post log_bauxdep_post log_coaldep_post iron_value baux_value coal_value"

eststo: ppmlhdfe antiattack `mainplus' ,a(st_dist hdate_st) cluster(st_dist) tol(1e-02)
			estadd ysumm

eststo: ppmlhdfe attack `mainplus' ,a(st_dist hdate_st)  cluster(st_dist) tol(1e-02)
			estadd ysumm


esttab using "$mytables/TableA9.tex", keep(log_irondep_post log_bauxdep_post log_coaldep_post)  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(ymean ysd N, labels("Mean DV" "Standard Deviation" "Observations") fmt(3 3 0)) replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore



*--------------------------------------------------------
*TABLE A10: Main Results with dummy mining measures
*--------------------------------------------------------

preserve
keep if mainsample_window==1

local main "iron_post iron_price"
local mainplus "iron_post baux_post coal_post iron_price baux_price coal_price"


 eststo: reghdfe antiattack_d `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_antiattack `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe hyp_antiattack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe attack_d `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

esttab using "$mytables/TableA10_PanelA.tex", keep(iron_post baux_post coal_post )  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(N N_clust, labels("Observations" "Clusters") fmt(0 0))   replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore

local main12 " iron2_post  iron2_price"
local mainplus12 "iron2_post baux2_post coal2_post iron2_price baux2_price coal2_price"

preserve
keep if mainsample_window==1
 eststo: reghdfe antiattack_d `main12', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_antiattack `main12', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe hyp_antiattack `mainplus12', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe attack_d `main12', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `main12', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `mainplus12', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

esttab using "$mytables/TableA10_PanelC.tex", keep(iron2_post baux2_post coal2_post)  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(N N_clust, labels("Observations" "Clusters") fmt(0 0))   replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore

local mainsmalldrop "ironsmalldrop_post ironsmalldrop_price"
local mainplussmalldrop "ironsmalldrop_post bauxsmalldrop_post coalsmalldrop_post iron_price baux_price coal_price"

preserve
keep if mainsample_window==1


 eststo: reghdfe antiattack_d `mainsmalldrop', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_antiattack `mainsmalldrop', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
	test ironsmalldrop_post
 eststo: reghdfe hyp_antiattack `mainplussmalldrop', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe attack_d `mainsmalldrop', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `mainsmalldrop', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `mainplussmalldrop', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

esttab using "$mytables/TableA10_PanelB.tex", keep(ironsmalldrop_post bauxsmalldrop_post coalsmalldrop_post)  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(N N_clust, labels("Observations" "Clusters") fmt(0 0))   replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore




*-----------------------------------------------------------
*TABLE A11: Main Results including manganese and chromite
*-----------------------------------------------------------

preserve

keep if mainsample_window==1

local mainplus "log_irondep_post log_bauxdep_post log_coaldep_post chromite_post manganese_post iron_value baux_value coal_value chromite_price manganese_price"

qui eststo: reghdfe antiattack_d `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
qui eststo: reghdfe hyp_antiattack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
qui eststo: reghdfe attack_d `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

qui eststo: reghdfe hyp_attack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

esttab using "$mytables/TableA11_PanelA.tex", keep(log_irondep_post log_bauxdep_post log_coaldep_post chromite_post manganese_post)  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(N N_clust, labels("Observations" "Clusters") fmt(0 0))   replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore


preserve
keep if mainsample_window==1

local mainplus2 "iron_post baux_post coal_post chromite_post manganese_post iron_price baux_price coal_price chromite_price manganese_price"

 eststo:reghdfe antiattack_d `mainplus2', a(hdate_st st_dist) cluster(st_dist)
			estadd ysumm

 eststo:reghdfe hyp_antiattack `mainplus2', a(hdate_st st_dist) cluster(st_dist)
			estadd ysumm

 eststo:reghdfe attack_d `mainplus2', a(hdate_st st_dist) cluster(st_dist)
			estadd ysumm


 eststo:reghdfe hyp_attack `mainplus2', a(hdate_st st_dist) cluster(st_dist)
			estadd ysumm

esttab using "$mytables/TableA11_PanelB.tex", keep(iron_post baux_post coal_post chromite_post manganese_post)  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(N N_clust, labels("Observations" "Clusters") fmt(0 0)) replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore


*----------------------------------------------
*TABLE A12: TRANSFORMATIONS OF MINING MEASURE 
*----------------------------------------------

preserve
keep if mainsample_window==1
local main "log_irondep_post iron_value"
local mainplus "log_irondep_post log_bauxdep_post log_coaldep_post iron_value baux_value coal_value"


 eststo: reghdfe antiattack_d `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_antiattack `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe hyp_antiattack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe attack_d `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

esttab using "$mytables/TableA12_main.tex", keep(log_irondep_post log_bauxdep_post log_coaldep_post)  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label  replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore


foreach suffix in "1000" "100" "10" "div10" "div100" "div1000" {
preserve
keep if mainsample_window==1

local main "log_irondep`suffix'_post iron_value`suffix'"
local mainplus "log_irondep`suffix'_post log_bauxdep`suffix'_post log_coaldep`suffix'_post iron_value`suffix' baux_value`suffix' coal_value`suffix'"

lab var log_irondep`suffix'_post "Log(Iron Deposit) x Post"
lab var log_bauxdep`suffix'_post "Log(Bauxite Deposit) x Post"
lab var log_coaldep`suffix'_post "Log(Coal Deposit) x Post"

 eststo: reghdfe antiattack_d `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_antiattack `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe hyp_antiattack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe attack_d `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

esttab using "$mytables/TableA12_`suffix'.tex", keep(log_irondep`suffix'_post log_bauxdep`suffix'_post log_coaldep`suffix'_post)  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label    replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore
}

*--------------------------------------------------------------
*TABLE A13: Results shutting down reallocation channels 
*--------------------------------------------------------------

preserve
keep if mainsample_window==1 

gen border_post=(border_sample*(irondepdum==0))*post

local main "log_irondep_post iron_value"

 eststo: reghdfe antiattack_d `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe antiattack_d `main' if (border_sample==0 | (irondepdum==1)), a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm	
		
 eststo: reghdfe antiattack_d `main' if (coaldepdum==0 & bauxdepdum==0), a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe hyp_antiattack `main' , a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe hyp_antiattack `main' if (border_sample==0 | (irondepdum==1)), a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

eststo: reghdfe hyp_antiattack `main' if (coaldepdum==0 & bauxdepdum==0), a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe attack_d `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe attack_d `main' if (border_sample==0 | (irondepdum==1)), a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm	
		
 eststo: reghdfe attack_d `main' if (coaldepdum==0 & bauxdepdum==0), a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe hyp_attack `main' , a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe hyp_attack `main' if (border_sample==0 | (irondepdum==1)), a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

eststo: reghdfe hyp_attack `main' if (coaldepdum==0 & bauxdepdum==0), a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm


esttab using "$mytables/TableA13.tex", keep(log_irondep_post)  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(ymean ysd N N_clust, labels("Mean DV" "Standard Deviation" "Observations" "Clusters") fmt(3 3 0 0))   replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore


*---------------------
*TABLE A14: WINDOWS 
*---------------------


local indep="log_irondep_post iron_value"
local counter=1
set more off
forvalues t=2(1)6{
preserve
local t_min=min(`t',4)
keep if inrange(hdate,98-`t_min',98-1+`t') 

qui eststo: xi: reghdfe hyp_antiattack `indep' if mainsample_full, a(hdate_st st_dist) cluster(st_dist)
			estadd ysumm

local counter=`counter'+1
restore
}

esttab using "$mytables/TableA14.tex", keep( `indep')  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(ymean ysd N N_clust, labels("Mean DV" "Standard Deviation" "Observations" "Clusters") fmt(3 3 0 0)) replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear


*---------------------------------------------------------------------------
*TABLE A15: Main Results shifting the treatment to the implementation period
*---------------------------------------------------------------------------

preserve
xtset st_dist hdate
gen log_irondep_post_shifted=f.log_irondep_post
gen log_bauxdep_post_shifted=f.log_bauxdep_post
gen log_coaldep_post_shifted=f.log_coaldep_post
lab var log_irondep_post_shifted "Log(Iron Deposit) x f.Post"
lab var log_bauxdep_post_shifted "Log(Bauxite Deposit) x f.Post"
lab var log_coaldep_post_shifted "Log(Coal Deposit) x f.Post"

keep if mainsample_window==1


local main "log_irondep_post_shifted iron_value"
local mainplus "log_irondep_post_shifted log_bauxdep_post_shifted log_coaldep_post_shifted iron_value baux_value coal_value"


 eststo: reghdfe antiattack_d `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_antiattack `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe hyp_antiattack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe attack_d `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

esttab using "$mytables/TableA15.tex",  keep(log_irondep_post_shifted log_bauxdep_post_shifted log_coaldep_post_shifted) fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(N N_clust, labels("Observations" "Clusters") fmt(0 0))   replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore


*-------------------------------------------------------
*TABLE A16: Main Results in sample for mining results
*-------------------------------------------------------


preserve
xtset st_dist hdate

keep if mainsample_window
                              
local main "log_irondep_post iron_value"
local main_dum "iron_post iron_price"

gen minselection=(irondepdum==1|manganesedepdum==1|chromitedepdum==1|bauxdepdum==1) 

foreach sample in "minselection" "minesample" {

 eststo: reghdfe antiattack_d `main' if `sample'==1, a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe hyp_antiattack `main' if `sample'==1, a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
	
		
 eststo: reghdfe attack_d `main' if `sample'==1, a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

		
 eststo: reghdfe hyp_attack `main' if `sample'==1, a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

		
esttab using "$mytables/TableA16_`sample'.tex",  keep(log_irondep_post) fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(ymean ysd N N_clust, labels("Mean DV" "Standard Deviation" "Observations" "Clusters") fmt(3 3 0 0))   replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
}

estimates clear
restore


*----------------------------------------------
*TABLE A17: Main Results in restricted samples
*----------------------------------------------

* Panel A: Dropping Jharkhand
preserve
keep if mainsample_window==1

gen JH=(state=="Jharkhand")
drop if JH==1

local main "log_irondep_post iron_value"
local mainplus "log_irondep_post log_bauxdep_post log_coaldep_post iron_value baux_value coal_value"


 eststo: reghdfe antiattack_d `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_antiattack `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe hyp_antiattack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe attack_d `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

esttab using "$mytables/TableA17_PanelA.tex",  keep(log_irondep_post log_bauxdep_post log_coaldep_post)  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(ymean ysd N N_clust, labels("Mean DV" "Standard Deviation" "Observations" "Clusters") fmt(3 3 0 0))   replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore

* Panel B: Dropping districts bordering iron ore districts
preserve
keep if mainsample_window==1 & border_sample==1

local main "log_irondep_post iron_value"
local mainplus "log_irondep_post log_bauxdep_post log_coaldep_post iron_value baux_value coal_value"


 eststo: reghdfe antiattack_d `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_antiattack `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe hyp_antiattack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe attack_d `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

esttab using "$mytables/TableA17_PanelB.tex", keep(log_irondep_post log_bauxdep_post log_coaldep_post)  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(ymean ysd N N_clust, labels("Mean DV" "Standard Deviation" "Observations" "Clusters") fmt(3 3 0 0))   replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore


* The replication of the publication materials ends here



***************************************************************************************************************************************
* The following additional results not included in the main paper nor online appendix
* This code is provided for completeness.
* These additional tables and figures are available on: https://www.parisschoolofeconomics.eu/en/vanden-eynde-oliver/
***************************************************************************************************************************************

*------------------------------------------------
*TABLE B1: Two-by-two comparisons
*------------------------------------------------

preserve

keep if mainsample_window==1
local main "iron_post"

gen sample=1
gen AP_drop=state!="Andhra Pradesh"
gen small_iron_drop=(iron2)|(log_irondep==0)

label var post "Post 2009"

foreach sample in "sample" "AP_drop" "small_iron_drop" {

 eststo: reg antiattack_d `main' irondepdum post if `sample', cluster(st_dist)
		estadd ysumm
 eststo: reg hyp_antiattack `main' irondepdum post if `sample', cluster(st_dist)
		estadd ysumm
 eststo: reg attack_d `main' irondepdum post if `sample', cluster(st_dist)
		estadd ysumm
 eststo: reg hyp_attack `main' irondepdum post if `sample', cluster(st_dist)
		estadd ysumm


esttab using "$mytables/TableB1_`sample'.tex",  fragment  nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(N N_clust, labels("Observations" "Clusters") fmt(0 0))   replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear


}

restore

*-----------------------------------------------------
*TABLE B2: Results in sample with any violence
*-----------------------------------------------------

preserve
keep if mainsample_window==1 

bys st_dist: egen max_antiattack_d=max(antiattack_d)
bys st_dist: egen max_attack_d=max(attack_d)

local main "log_irondep_post iron_value"
local mainplus "log_irondep_post log_bauxdep_post log_coaldep_post iron_value baux_value coal_value"


 eststo: reghdfe antiattack_d `main' if max_antiattack_d!=0 & max_antiattack_d!=., a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_antiattack `main'  if max_antiattack_d!=0 & max_antiattack_d!=., a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe hyp_antiattack `mainplus'  if max_antiattack_d!=0 & max_antiattack_d!=., a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe attack_d `main'  if max_attack_d!=0 & max_attack_d!=., a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `main'  if max_attack_d!=0 & max_attack_d!=., a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe hyp_attack `mainplus'  if max_attack_d!=0 & max_attack_d!=., a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

esttab using "$mytables/TableB2.tex", keep(log_irondep_post log_bauxdep_post log_coaldep_post)  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(ymean ysd N N_clust, labels("Mean DV" "Standard Deviation" "Observations" "Clusters") fmt(3 3 0 0))   replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore



*---------------------------------------------
*TABLE B3: MAIN RESULTS with log(x+1) outcome
*---------------------------------------------

preserve
keep if mainsample_window==1

local main "log_irondep_post iron_value"
local mainplus "log_irondep_post log_bauxdep_post log_coaldep_post iron_value baux_value coal_value"

 eststo: reghdfe log_antiattack `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm
		
 eststo: reghdfe log_antiattack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe log_attack `main', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

 eststo: reghdfe log_attack `mainplus', a(hdate_st st_dist) cluster(st_dist)
		estadd ysumm

esttab using "$mytables/TableB3.tex", keep(log_irondep_post log_bauxdep_post log_coaldep_post)  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(ymean ysd N N_clust, labels("Mean DV" "Standard Deviation" "Observations" "Clusters") fmt(3 3 0 0))   replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par)) substitute((.) "" 0.000 "")
estimates clear
restore

*/

*-------------------------
*TABLE B4: Time Patterns
*-------------------------


foreach mineral in "iron" "baux" "coal"  {

preserve

keep if mainsample_full==1
local main "`mineral'_post1 `mineral'_post2"
local value " `mineral'_value"
local timeint "i.post|percentageforest i.post|dist_pct_app_pr i.post|r_tot_scst_rate i.post|r_tot_lit i.post|pop_dens i.post|percentage_drought i.post|dist_pct_power i.post|r_share i.post|r_tot_anyag_rate"

* Make sure that interaction variables are consistent with those used earlier

gen `mineral'_post1=(log_`mineral'dep)*inrange(hdate,98,103)
gen `mineral'_post2=(log_`mineral'dep)*inrange(hdate,104,107)

label var `mineral'_post1 "Log(`mineral' dep) x 2009-2011"
label var `mineral'_post2 "Log(`mineral' dep) x 2012-2013"

 eststo: reghdfe hyp_antiattack `main' `value' , a(hdate_st st_dist) cluster(st_dist)
			estadd ysumm

 eststo: xi: reghdfe hyp_antiattack `main'  `value' `timeint', a(hdate_st st_dist) cluster(st_dist)
			estadd ysumm

 eststo: reghdfe hyp_attack `main'  `value' , a(hdate_st st_dist) cluster(st_dist)
			estadd ysumm

 eststo: xi: reghdfe hyp_attack `main'  `value' `timeint', a(hdate_st st_dist) cluster(st_dist)
			estadd ysumm

if "`mineral'"=="coal" {
esttab using "$mytables/TableB4_`mineral'.tex", keep(`main')  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(ymean ysd N N_clust, labels("Mean DV" "Standard Deviation" "Observations" "Clusters") fmt(3 3 0 0)) replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par))
estimates clear
}
else {
esttab using "$mytables/TableB4_`mineral'.tex", keep(`main')  fragment nomtitles nonumbers  nowrap booktabs  nogaps  nolines eqlabels("") style(tex) wide label stats(N N_clust, labels("Observations" "Clusters") fmt(0 0)) replace starlevels(* 0.10 ** 0.05 *** 0.01) collabels(none)  cells(b(star fmt(%9.3f)) se(par))
estimates clear
}
restore

}




*---------------------------------------------------------------------------
*FIGURE B1: Distribution of the transformed iron ore deposit measure
*---------------------------------------------------------------------------


foreach suffix in "1000" "100" "10" "div10" "div100" "div1000" {
label var log_irondep`suffix'_post "Log(Iron Deposit), positive"
histogram log_irondep`suffix'_post if hdate==100 & mainsample_full==1 & irondepdum==1, scheme(s1mono)
graph export "$myfigures/FigureB1_`suffix'.pdf", replace
label var log_irondep`suffix'_post "Log(Iron Deposit) x Post"
}




*---------------------------------------------------------------------------
*FIGURE B2: Raw time series
*---------------------------------------------------------------------------

set matsize 2000


preserve

keep if mainsample_full 

matrix hrid = J(24 ,8, 0)

forvalues time=94(1)107 {
gen time_`time'=(hdate==`time')*(irondepdum==0)

}


foreach outcome in  "antiattack_d"  "antiattack_pc" "hyp_antiattack"  "hyp_attack" "attack_d" "attack_pc"  "antiattack" "attack" {

foreach mineral in "iron" {

foreach measure in "" {

qui xi: reg `outcome' `mineral'dep`measure'94 `mineral'dep`measure'95 `mineral'dep`measure'96 `mineral'dep`measure'97 `mineral'dep`measure'98 `mineral'dep`measure'99 `mineral'dep`measure'100 `mineral'dep`measure'101 `mineral'dep`measure'102 `mineral'dep`measure'103 `mineral'dep`measure'104 `mineral'dep`measure'105 `mineral'dep`measure'106 `mineral'dep`measure'107  time_*, nocons cluster(st_dist)

global iter  = 1
forvalues i=94(1)107 {
  qui lincom  `mineral'dep`measure'`i'
  matrix hrid[$iter,3] = `r(estimate)'
  matrix hrid[$iter,2] = `r(estimate)' - 1.98 * `r(se)'
  matrix hrid[$iter,4] = `r(estimate)'+ 1.98* `r(se)'
  local ttt=`i'-98
  matrix hrid[$iter, 1] = `ttt'
  matrix hrid[$iter, 5] = 1
  qui lincom  time_`i'
  matrix hrid[$iter, 7] = `r(estimate)'
  matrix hrid[$iter, 6] = `r(estimate)' - 1.98 * `r(se)'
  matrix hrid[$iter, 8] = `r(estimate)'+ 1.98* `r(se)'
  local ttt=`i'-98  
  global iter=$iter+1
  }

  svmat hrid
sort hrid1

qui su hrid2
local miny = `r(min)'
qui su hrid4
local maxy = `r(max)'
drop if hrid1==0 & hrid2==0 & hrid3==0 & hrid5==0

qui su hrid1
sort hrid1
twoway (connected hrid3 hrid1 ,ytitle("Coefficient estimate", axis(1))) (rcap hrid2 hrid4 hrid1 , lcolor(gs4) lwidth(vthin) xline(-0.5,lcolor(red))) (connected hrid7 hrid1 , lpattern(dash) ytitle("Coefficient estimate", axis(1))) (rcap hrid6 hrid8 hrid1 , lcolor(gs4) lwidth(vthin) xline(-0.5,lcolor(red))), scheme(s1mono) legend(off) xtitle("Half-years to treatment", size(4)) xscale(range(`r(min)' `r(max)')) yline(0, lp(dot) lwidth(vthin))
graph export "$myfigures/FigureB2_`outcome'.png", replace
drop hrid*

}
}
}

restore

* END
